package nowCoder;

import java.util.Arrays;
import java.util.Scanner;

public class HJ93 {
    // 1 2 3 4 5 6 7 8 9 11
    // 5 1 4 7 11   28
    // 3 6 9 8 2    28
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int aa = 0;
        int[] b = new int[n];
        int bb = 0;
        int[] c = new int[n];
        int cc = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (x % 5 == 0){
                aa += x;
                a[i] = x;
                continue;
            }
            if (x % 3 == 0){
                bb += x;
                b[i] = x;
                continue;
            }
            cc += x;
            c[i] = x;
        }
        boolean b1 = (aa + bb + cc) % 2 == 0;
//        if (b1)
//            System.out.println(dy());
//        else
//            System.out.println(false);
        System.out.println(Arrays.toString(a));
        System.out.println(Arrays.toString(b));
        System.out.println(Arrays.toString(c));
    }
//    public static boolean dy(int[] source, int[] teg, )
}
